package com.ruoyi.algorithm.controller;

import com.ruoyi.algorithm.model.OperatorModel;
import com.ruoyi.algorithm.service.DemoService;
import com.ruoyi.algorithm.util.ReflectionUtil;
import com.beihu.sightplus.common.request.PageRequest;
import com.beihu.sightplus.common.response.ResultData;
import com.beihu.sightplus.common.string.MyStringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.lang.reflect.Field;
import java.sql.Timestamp;


@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private DemoService demoService;

    /**
     * 分页查询
     */
    @GetMapping("/pageList")
    public ResultData pageList(PageRequest pageRequest) {
        return ResultData.success(demoService.pageList(pageRequest));
    }

    /**
     * 上传文件
     */
    @PostMapping("/uploadFile")
    public ResultData uploadPic(@RequestParam("file") MultipartFile file) {
        return demoService.uploadPic(file);
    }

    /**
     * 测试中文转拼音
     */
    @PostMapping("/testConvertToEnglish")
    public String testConvertToEnglish(){
        String textChina = "Help";
        return MyStringUtil.getChineseToPinyin(textChina);
    }

    /**
     * 生成主键(以当前时间戳)
     */
    @GetMapping("/getId")
    public String getId(){
        return new Timestamp(System.currentTimeMillis()).getTime() + "";
    }

    /**
     * 获取父类
     */
    @GetMapping("/getParentClass")
    public void getParentClass(){
        OperatorModel operatorModel = new OperatorModel();
        Class<?> superclass = operatorModel.getClass().getSuperclass();
        Field[] declaredField = superclass.getDeclaredFields();
        for (Field field : declaredField) {
            System.out.println("---------" + field.toString());
        }
    }

    /**
     * 获取本类，指定属性的匹配方式(like还是=)
     */
    @GetMapping("/getTableFieldMatchType")
    public String getTableFieldMatchType() {
        OperatorModel operatorModel = new OperatorModel();
        return ReflectionUtil.getTableFieldMatchType(operatorModel.getClass(), "name");
    }



}
